package main

import (
	"fmt"
)

func maxIncreaseKeepingSkyline(grid [][]int) int {
	var sum int = 0
	maxRow := make([]int, len(grid))
	maxCol := make([]int, len(grid[0]))
	for i, v := range grid {
		for j, v2 := range v {
			if v2 > maxRow[j] {
				maxRow[j] = v2
			}
			if v2 > maxCol[i] {
				maxCol[i] = v2
			}
		}
	}
	for i, v := range grid {
		for j, v2 := range v {
			var v = maxCol[i]
			if maxCol[i] > maxRow[j] {
				v = maxRow[j]
			}
			sum += v - v2
		}
	}
	return sum
}

func main() {
	array := [][]int{
		{3, 0, 8, 4},
		{2, 4, 5, 7},
		{9, 2, 6, 3},
		{0, 3, 1, 0}}
	fmt.Println(35 == maxIncreaseKeepingSkyline(array))
}
